<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>instanceof</h1>
<hr>

<script>

    //1.typeof  typeof方法返回一个字符串，来表示数据的类型。
    /*
    function Person(name,age){
        this.name = name;
        this.age = age;
    }
    let p = new Person('zhangsna',20);
    let d = new Date();
    let arr = new Array();
    let num = new Number(100);

    console.log(typeof(undefined));
    console.log(typeof(null));
    console.log(typeof(100));
    console.log(typeof(true));
    console.log(typeof("hello"));
    console.log(typeof({}));
    console.log(typeof(Person));
    console.log(typeof(p));
    console.log(typeof(d));
    console.log(typeof(arr));
    console.log(typeof(num));
    */


    //2.instanceof

    /*
    let num = 100;
    console.log(num instanceof Number);
    num  = new Number(num);
    console.log(num instanceof Number);


    let p1 = {
        name : 'zhangsan',
        age : 18
    }

    function Person(name,age){
        this.name = name;
        this.age = age;
    }
    let p2 = new Person('lisi',18);

    console.log(p1 instanceof Object);
    console.log(p1 instanceof Person);
    console.log(p2 instanceof Object);
    console.log(p2 instanceof Person);
    */

    //但是instanceof更准确的解释是：判断一个构造函数的prototype属性所指向的对象是否在另一个被检测对象的原型链上。

    let p1 = {
        name : 'zhangsan',
        age : 18
    }

    function Person(name,age){
        this.name = name;
        this.age = age;
    }
    let p2 = new Person('lisi',18);

    Person.prototype = p1;

    console.log(p1 instanceof Object);
    console.log(p1 instanceof Person);
    console.log(p2 instanceof Object);
    console.log(p2 instanceof Person);
</script>
</body>
</html>